package anthology.daily_question._25_01;

import java.util.Map;
import java.util.TreeMap;

//https://leetcode.cn/problems/my-calendar-iii/description/?envType=daily-question&envId=2025-01-04
public class _0732我的日程安排表3 {
    class MyCalendarThree {
        private TreeMap<Integer, Integer> cnt;

        public MyCalendarThree() {
            cnt = new TreeMap<Integer, Integer>();
        }

        public int book(int start, int end) {
            int ans = 0;
            int maxBook = 0;
            cnt.put(start, cnt.getOrDefault(start, 0) + 1);
            cnt.put(end, cnt.getOrDefault(end, 0) - 1);
            for (Map.Entry<Integer, Integer> entry : cnt.entrySet()) {
                int freq = entry.getValue();
                maxBook += freq;
                ans = Math.max(maxBook, ans);
            }
            return ans;
        }
    }
}
